package com.qq.controller;

import com.qq.model.Customer;
import com.qq.model.Orders;
import com.qq.service.CustomerService;
import com.qq.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("login")
public class loginController {

    @Autowired
    OrderService orderService;

    @RequestMapping("view")
    String view() {
        return "login/view";
    }

    //进行登录
    @RequestMapping("doLogin")
    String doLogin(String mobile, HttpSession session) {
        session.setMaxInactiveInterval(30 * 60);
        Orders orders = orderService.selectOrders(mobile);
        if (orders != null) {
            session.setAttribute("ORDERS", orders);
            return "redirect:list";
        } else {
            return "redirect:view";
        }
    }

    @RequestMapping("list")
    String list(HttpServletRequest request, HttpSession session) {
        Orders orders = (Orders) session.getAttribute("ORDERS");
        request.setAttribute("orders", orders);
        return "login/list";
    }

    //注销功能
    @RequestMapping("logout")
    String logout(HttpSession session) {
        session.removeAttribute("ORDERS");
        return "redirect:view";
    }
}
